home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / Remove Custom Icons < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.5 KB  |  171 lines  |  [TEXT/ToyS]

  1. -- Properties
  2. property kasPrefName : "Image Icons V1.0"
  3.  
  4. -- Globals
  5. global gasInfoWind -- Info window
  6. global gasInfoPos -- Position of info window
  7. global gasDrawing -- Draw window
  8. global gasDrawPos
  9.  
  10. global gasFoldersToDo -- The folders left to process
  11. global gasShown -- Number gone!
  12. global gasChecked -- Number checked!
  13.  
  14.  
  15. on open fsObjs
  16.     -- Load prefs, show window
  17.     pfLoad()
  18.     
  19.     -- Set up prefix
  20.     set gasShown to 0
  21.     set gasChecked to 0
  22.     set gasShowWind to 0
  23.     
  24.     set gasInfoWind to display info titled kasPrefName ¬
  25.         located at gasInfoPos ¬
  26.         message "Scanning…"
  27.     
  28.     -- Do files
  29.     set gasFoldersToDo to {}
  30.     
  31.     repeat with fsObj in fsObjs
  32.         set myInfo to (basic info for fsObj)
  33.         
  34.         if (system type of myInfo is "fold") then
  35.             DoOne(fsObj)
  36.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  37.         else
  38.             DoOne(fsObj)
  39.         end if
  40.     end repeat
  41.     
  42.     -- Do folders
  43.     repeat while gasFoldersToDo is not {}
  44.         -- Pop one off the end
  45.         set n to the number of items of gasFoldersToDo
  46.         set fsObj to item n of gasFoldersToDo
  47.         
  48.         if (n > 1) then
  49.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  50.         else
  51.             set gasFoldersToDo to {}
  52.         end if
  53.         
  54.         display info gasInfoWind ¬
  55.             message ("Folders to go: " & n) ¬
  56.             at line 6 ¬
  57.             using color (15 * 32)
  58.         
  59.         -- Process it
  60.         GoDeep(fsObj)
  61.     end repeat
  62.     
  63.     display info gasInfoWind message "DONE!"
  64.     
  65.     pause for 5 with seconds timing -- Let screen wait...
  66.     
  67.     set gasInfoPos to screen location of ¬
  68.         (display info gasInfoWind with disposal)
  69.     
  70.     pfSave() -- Save window location
  71. end open
  72.  
  73.  
  74. on DoOne(fsObj)
  75.     set fInfo to (extended info for fsObj)
  76.     set fname to (catalog name of fInfo)
  77.     
  78.     display info gasInfoWind ¬
  79.         message fname ¬
  80.         at line 2
  81.     
  82.     if (custom icon status of fInfo) then
  83.         display info gasInfoWind ¬
  84.             message ¬
  85.             "Removing…" at line 3
  86.         -- Get Picture / Assign Icon
  87.         set the icon of fsObj with to its default
  88.     else
  89.         display info gasInfoWind ¬
  90.             message ¬
  91.             "No custom icon." at line 3
  92.     end if
  93. end DoOne
  94.  
  95.  
  96. on GoDeep(foldObj)
  97.     display info gasInfoWind ¬
  98.         message "Path: " & (foldObj as string)
  99.     
  100.     set daddy to foldObj as string
  101.     
  102.     -- Do kinds that match
  103.     display info gasInfoWind ¬
  104.         message "Scanning files" at line 5
  105.     
  106.     set myItems to the entries in foldObj ¬
  107.         whose kinds are a file
  108.     
  109.     repeat with myItem in myItems
  110.         DoOne((daddy & myItem) as alias)
  111.     end repeat
  112.     
  113.     -- Do folders
  114.     display info gasInfoWind ¬
  115.         message "Scanning subfolders" at line 5
  116.     
  117.     set myItems to the entries in foldObj ¬
  118.         whose kinds are a folder
  119.     
  120.     repeat with myItem in myItems
  121.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  122.     end repeat
  123.     
  124.     -- Done
  125.     display info gasInfoWind ¬
  126.         message "…" at line 5
  127. end GoDeep
  128.  
  129.  
  130. on PlaceInCenter(src, dst)
  131.     set sW to (item 3 of src) - (item 1 of src)
  132.     set sH to (item 4 of src) - (item 2 of src)
  133.     set dW to (item 3 of dst) - (item 1 of dst)
  134.     set dH to (item 4 of dst) - (item 2 of dst)
  135.     
  136.     set r to dW / sW
  137.     set rH to dH / sH -- ratios
  138.     
  139.     if (rH < r) then set r to rH
  140.     
  141.     -- Round to a .25 ratio if > 1
  142.     if (r > 1) then ¬
  143.         set r to 0.25 * (round (r * 4))
  144.     
  145.     -- Scale the src
  146.     set sW to round (sW * r)
  147.     set sH to round (sH * r)
  148.     set mW to round ((dW - sW) / 2) + (item 1 of dst)
  149.     set mH to round ((dH - sH) / 2) + (item 2 of dst)
  150.     
  151.     -- Center it
  152.     return {mW, mH, mW + sW, mH + sH}
  153. end PlaceInCenter
  154.  
  155.  
  156. on pfLoad()
  157.     try
  158.         set ourPrefs to (load preference named kasPrefName)
  159.     on error
  160.         set ourPrefs to {{8, 48}, {8, 112}}
  161.     end try
  162.     
  163.     set gasInfoPos to item 1 of ourPrefs
  164.     set gasDrawPos to item 2 of ourPrefs
  165. end pfLoad
  166.  
  167.  
  168. on pfSave()
  169.     save preference {gasInfoPos, gasDrawPos} named kasPrefName
  170. end pfSave
  171.